CC=gcc
RPC_SYSTEM=rpc.o
CLIENT_MAIN=client.o
SERVER_MAIN=server.o
RPC_SYSTEM_A=rpc.a
FLAGS= -Wall

.PHONY: format all

all: $(RPC_SYSTEM) rpc-client rpc-server $(RPC_SYSTEM_A)

rpc: $(RPC_SYSTEM)

$(RPC_SYSTEM): rpc.c rpc.h helper.h
	$(CC) $(FLAGS) -c -o $@ $<

$(CLIENT_MAIN): client.c
	$(CC) $(FLAGS) -c -o $@ $^

$(SERVER_MAIN): server.c
	$(CC) $(FLAGS) -c -o $@ $^

rpc-client: $(RPC_SYSTEM) $(CLIENT_MAIN)
	$(CC) $(FLAGS) -o $@ $^

rpc-server: $(RPC_SYSTEM) $(SERVER_MAIN)
	$(CC) $(FLAGS) -o $@ $^

$(RPC_SYSTEM_A): $(RPC_SYSTEM)
	ar rcs $(RPC_SYSTEM_A) $(RPC_SYSTEM)

format:
	clang-format -style=file -i *.c *.h

clean:
	rm -f rpc-client rpc-server *.o *.a
